﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebComponents;
using System.IO;

public partial class Admin_Controls_Common_ImagePath : System.Web.UI.UserControl {
  private string _ImagePath = "";
  public string ImagePath {
    get { return txtImage.Text; }
    set { _ImagePath = value; }
  }
  private string _ImageUrl = "";
  public string ImageUrl {
    get { return _ImageUrl; }
    set { _ImageUrl = value; }
  }
  public string FileType {
    get {
      if (ImagePath != "")
        return ImagePath.Substring(ImagePath.LastIndexOf("."));
      return "";
    }
  }
  private bool _RequiredFieldValidator = false;  
  public bool RequiredFieldValidator {
    get { return _RequiredFieldValidator; }
    set { _RequiredFieldValidator = value; }
  }
  private string _MediaTitle = "";

  public string MediaTitle {
    get { return _MediaTitle; }
    set { _MediaTitle = value; }
  }
  public double FileSize {
    get {
      if (ImagePath != "") {
        if (File.Exists(Server.MapPath("../" + ImagePath))) {
          FileInfo fInfo = new FileInfo(Server.MapPath("../" + ImagePath));
          return ConvertType.ToDouble(fInfo.Length.ToString());
        } else
          return 0.0;
      } else
        return 0.0;
    }
  }
  protected void Page_Load(object sender, EventArgs e) {
    if (ImageUrl == "")
      imageURL.ImageUrl = Global.NoImagePath;
    else
      imageURL.ImageUrl = Global.ApplicationPath + string.Format("Admin/Image.ashx?FileUrl=../{0}&Size=130", ImageUrl);
    txtImage.Text = ImageUrl;
    RequiredFieldValidator1.Visible = RequiredFieldValidator;
    if (MediaTitle != "")
      lblTitle.Text = MediaTitle;
  }
}
